package com.example.chat_matching.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

@Data
@Component
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    @Getter
    private Integer code;
    @Getter
    private String message;
    @Getter
    private T data;

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }
    public static Result success(){
        return new Result(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
    }
    public static<T> Result<T> success(T data){
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }
    public static Result success(String message){
        return new Result(ResultCode.SUCCESS.getCode(),message);
    }
    public static Result failed(){
        return new Result(ResultCode.FAIL.getCode(), ResultCode.FAIL.getMessage());
    }
    public static Result failed(String message){
        return new Result(ResultCode.FAIL.getCode(), message);
    }

    public static Result failed(ResultCode code){
        return new Result(code.getCode(),code.getMessage());
    }


}
